import { createI18n } from "vue-i18n";
import { EnumLocalStorageKey } from "@/enums/localStorage"
import vxeTablzhCN from 'vxe-table/lib/locale/lang/zh-CN'
import vxeTableenUS from 'vxe-table/lib/locale/lang/en-US'
const zhCNModules = import.meta.glob("./modules/*/zh-CN.ts",{eager:true,import:'default'});
let zhCNResult = {...vxeTablzhCN}

Object.keys(zhCNModules).forEach((key) => {
  const defaultModule = zhCNModules[key];
  if (!defaultModule) return;
  Object.assign(zhCNResult, defaultModule)
});

const enUSModules = import.meta.glob("./modules/*/en-US.ts",{eager:true,import:'default'});
let enUSResult = {...vxeTableenUS}

Object.keys(enUSModules).forEach((key) => {
  const defaultModule = enUSModules[key];
  if (!defaultModule) return;
  Object.assign(enUSResult,defaultModule)
});

const defaultLocale = localStorage.getItem(EnumLocalStorageKey.CampusAdminLocale) || "zh-CN";

const i18n = createI18n({
  locale: defaultLocale,
  fallbackLocale: "en-US",
  allowComposition: true,
  messages: {
    "en-US": enUSResult,
    "zh-CN": zhCNResult,
  },
});

export default i18n;
